package dt.member;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.io.IOException;
import java.io.Reader;

public class memberJoinAction extends ActionSupport {
	
	public static Reader reader;  // ���� ��Ʈ���� ���� reader
	public static SqlMapClient sqlMapper; // SqlMapClient API�� ����ϱ� ���� sqlMapper ��ü

	private memberVO paramClass;  // �Ķ���͸� ������ ��ü
	private memberVO resultClassId; // ���� ��� ���� ������ ��ü
	private memberVO resultClassNick; // ���� ��� ���� ������ ��ü
	
	private String id;
	private String passwd;;
	private String nickname;
	private String name;
	private String jumin1;
	private String jumin2;
	private String email;
	private String mobile1;
	private String mobile2;
	private String mobile3;
	private String phone1;
	private String phone2;
	private String phone3;
	private String zip;
	private String addr1;
	private String addr2;
	
	private int chkJoin;
	
	private int BoardFlag;
	
	//����
	public memberJoinAction() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); //sqlMapConfig.xml ������ ���������� �����´�.
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); //sqlMapConfig.xml ������ ����� sqlMapper ��ü ��
		reader.close();
	}
	
	public String form() throws Exception {
		//����� 
		return SUCCESS;
	}
	
	// ȸ���� memberJoin �׼�
	public String execute() throws Exception {
		
		// �Ķ���Ϳ� ����Ʈ ��ü ��
		paramClass = new memberVO();
		resultClassId = new memberVO();
		resultClassNick = new memberVO();
		
		resultClassId = (memberVO) sqlMapper.queryForObject("getMember", getId());
		resultClassNick = (memberVO) sqlMapper.queryForObject("nickCheck", getNickname());
		
		// ���̵�� ������ DB�� �������� ������ ȸ������ �����Ѵ�.
		if((resultClassId==null) && (resultClassNick==null)) {
			//����� �׸� ����
			paramClass.setId(getId());
			paramClass.setPasswd(getPasswd());
			paramClass.setNickname(getNickname());
			paramClass.setName(getName());
			paramClass.setJumin1(getJumin1());
			paramClass.setJumin2(getJumin2());
			paramClass.setEmail(getEmail());
			paramClass.setMobile1(getMobile1());
			paramClass.setMobile2(getMobile2());
			paramClass.setMobile3(getMobile3());
			paramClass.setPhone1(getPhone1());
			paramClass.setPhone2(getPhone2());
			paramClass.setPhone3(getPhone3());
			paramClass.setZip(getZip());
			paramClass.setAddr1(getAddr1());
			paramClass.setAddr2(getAddr2());

			//��� ���� ����
			sqlMapper.insert("insertMember", paramClass);
			
			return SUCCESS;
		}
		else {
			// ���� ���ԵǾ� ���̵� �����ϸ�
			if(!(resultClassId == null)) {
				chkJoin = -1;
				System.out.println(chkJoin);
				return INPUT;
			}
			// ���� ���ԵǾ� �ִ� ������ �����ϸ�
			else {
				chkJoin = 1;
				System.out.println(chkJoin);
				return INPUT;
			}
		}
		
		
	}

	public static Reader getReader() {
		return reader;
	}

	public static void setReader(Reader reader) {
		memberJoinAction.reader = reader;
	}

	public static SqlMapClient getSqlMapper() {
		return sqlMapper;
	}

	public static void setSqlMapper(SqlMapClient sqlMapper) {
		memberJoinAction.sqlMapper = sqlMapper;
	}

	public memberVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(memberVO paramClass) {
		this.paramClass = paramClass;
	}

	public memberVO getResultClassId() {
		return resultClassId;
	}

	public void setResultClassId(memberVO resultClassId) {
		this.resultClassId = resultClassId;
	}

	public memberVO getResultClassNick() {
		return resultClassNick;
	}

	public void setResultClassNick(memberVO resultClassNick) {
		this.resultClassNick = resultClassNick;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getJumin1() {
		return jumin1;
	}

	public void setJumin1(String jumin1) {
		this.jumin1 = jumin1;
	}

	public String getJumin2() {
		return jumin2;
	}

	public void setJumin2(String jumin2) {
		this.jumin2 = jumin2;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile1() {
		return mobile1;
	}

	public void setMobile1(String mobile1) {
		this.mobile1 = mobile1;
	}

	public String getMobile2() {
		return mobile2;
	}

	public void setMobile2(String mobile2) {
		this.mobile2 = mobile2;
	}

	public String getMobile3() {
		return mobile3;
	}

	public void setMobile3(String mobile3) {
		this.mobile3 = mobile3;
	}

	public String getPhone1() {
		return phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	public String getPhone2() {
		return phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public String getPhone3() {
		return phone3;
	}

	public void setPhone3(String phone3) {
		this.phone3 = phone3;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getAddr1() {
		return addr1;
	}

	public void setAddr1(String addr1) {
		this.addr1 = addr1;
	}

	public String getAddr2() {
		return addr2;
	}

	public void setAddr2(String addr2) {
		this.addr2 = addr2;
	}

	public int getChkJoin() {
		return chkJoin;
	}

	public void setChkJoin(int chkJoin) {
		this.chkJoin = chkJoin;
	}
	
	public int getBoardFlag() {
		return BoardFlag;
	}

	public void setBoardFlag(int BoardFlag) {
		this.BoardFlag = BoardFlag;
	}
	
	
}